package com.songlanyun.modules.message.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.songlanyun.common.enums.GoodsConstant;
import com.songlanyun.common.enums.MarketingConstant;
import com.songlanyun.common.enums.PrivateMessageConstant;
import com.songlanyun.common.enums.SysConstant;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.message.entity.PrivateMessage;
import com.songlanyun.modules.message.model.GoodsMessage;
import com.songlanyun.modules.message.model.LogisticsMessage;
import com.songlanyun.modules.message.model.PayMessage;
import com.songlanyun.modules.message.model.to.PrivateMessageTO;
import com.songlanyun.modules.message.model.vo.PrivateMessageVO;
import com.songlanyun.modules.message.model.vo.UnreadMessageVO;
import com.songlanyun.modules.message.service.PrivateMessageService;
import com.songlanyun.modules.rabbitmq.MqConstant;
import com.songlanyun.modules.rabbitmq.service.MessageHelper;
import com.songlanyun.modules.rabbitmq.service.SendMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * app站内消息
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2021-03-04 16:05:09
 */
@RestController
@RequestMapping("api/private/message")
public class PrivateMessageApiController extends AbstractApiController {
    @Autowired
    private PrivateMessageService privateMessageService;

    /**
     * 会员统计所有站内消息未读数量
     *
     * @return
     */
    @GetMapping("/unread-num")
    public R unreadNum() {
        Integer count = this.privateMessageService.unreadNum(getUserId(true));
        return R.ok().put("data", count);
    }

    /**
     * 会员根据类型来查询未读消息数据列表
     *
     * @return
     */
    @GetMapping("/unread-info")
    public R unreadInfo() {
        List<UnreadMessageVO> vos = this.privateMessageService.unreadInfo(getUserId(true));
        return R.ok().put("list", vos);
    }

    /**
     * 会员根据类型来查询消息数据
     *
     * @return
     */
    @GetMapping("/list/{type}")
    public R listType(@PathVariable("type") Integer type, @RequestParam Map<String, Object> params) {
        params.put("type",type);
        params.put("userId",getUserId(true));
        PageUtils page = this.privateMessageService.listType(params);
        return R.ok().put("page", page);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        PrivateMessageVO vo = this.privateMessageService.info(id);
        return R.ok().put("data", vo);
    }

    /**
     * 根据类型来设置消息为已读
     *
     * @return
     */
    @PostMapping("/read-type/{type}")
    public R readType(@PathVariable("type") Integer type) {
        privateMessageService.readType(type, getUserId(true));
        return R.ok();
    }

}
